<template>
    <div class="pet">
         <div class="photo">
            <div class="head">
                <van-icon name="arrow-left"
                size="0.8rem"
                class="back-icon"
                @click="goback()" /> 
            </div>
            <van-image v-if="pet.profile" :src="pet.profile"
             alt="" class="pet-img">
                <template v-slot:loading>
                    <van-loading type="spinner" size="18" />
                </template>
            </van-image> 
        </div>
        <div class="pet-Info">
            <h2>{{pet.pname}}
                <svg class="icon gender" aria-hidden="true" v-if="pet.gender === 'male'">
                    <use xlink:href="#icon-nv"></use>
                </svg>
                <svg class="icon gender" aria-hidden="true" v-if="pet.gender === 'female'">
                    <use xlink:href="#icon-nan"></use>
                </svg>
            </h2>
            <p class="type">{{pet.type}}</p>
            <div class="charact">
                <p class="charact-item" v-for="(charactItem,index) in pet.charact" :key="index">{{charactItem}}</p>
            </div>
            <div class="detail">
                <div class="detail-item">
                    <p>身高</p>
                    <span class="detail-item-name">{{pet.height}}cm</span>
                </div>
                <div class="detail-item">
                    <p>体重</p>
                    <span class="detail-item-name">{{pet.weight}}kg</span>
                </div>
                <div class="detail-item">
                    <p>身形</p>
                    <span class="detail-item-name">{{pet.size}}</span>
                </div>
                <div class="detail-item">
                    <p>颜色</p>
                    <span class="detail-item-name">{{pet.color}}</span>
                </div>

            </div>
            <div class="why">
                为什么我在这里？
                <p class="reason">
                   {{pet.reason}}
                </p>
            </div>
            <div class="belong" v-if="pet.belong">               
                <div class="belong-info">
                    <img v-if="pet.belong.profile" :src="pet.belong.profile" alt="" class="agency-img">                    
                    <div>{{pet.belong.real_name}}
                        <p class="belong-text">Adoption Agency</p>
                    </div>                    
                </div>
                <svg class="icon chat-icon" aria-hidden="true">
                    <use xlink:href="#icon-xinxi-01"></use>
                </svg>
            </div>
            <P-button class="button" @click.native="gotoApporint()">收养{{pet.pname}}</P-button>
        </div>
    </div>
</template>
<script>
import PButton from '@/components/button'
import { getpetInfo,getAgencyInfo } from "@/api.js";
export default {
    data() {
        return{
            pet:{}
        }
    },
    components:{
        PButton
    },
    created() {
        this.getPetInfo()
    },
    methods:{
        gotoApporint(){
          let id = this.$route.params.id
          let aid = this.pet.belong.aid
          this.$router.push(`/apporint/${id}/${aid}`)
        },
        goback(){
            this.$router.go(-1)
        },
        async getPetInfo() {
            let params = {id:this.$route.params.id}
            await getpetInfo(params).then(res => {
                this.pet = res.data[0]              
                let petBelong = this.pet.belong
                console.log(this.pet)
                this.getAgencyInfo({aid:petBelong})
            })
        },
        async getAgencyInfo(belong) {
          const {data} = await getAgencyInfo(belong)
          this.pet.belong = data
        }
    }
}
</script>
<style lang="less" scoped>
.pet{
    .photo{
        height: 6rem;
        overflow:hidden;
        .head{
            padding:0.5rem 0.25rem 0;
            width: 100%;
            height: 1.25rem;
            position: absolute;
            z-index: 999;
            display: flex;
            justify-content: space-between;
            .pet-icon{
                width: 0.7rem;
                color: black;
            }
        }
        .pet-img{
            width: 100%;
        }
    }
    .pet-Info{
        padding:0.5rem;
        .gender {
            width: 0.7rem;
            height: 1em;
            margin-left: 0.2rem;
        }
        .type{
            margin-top: 0.25rem;
            font-size: 0.5rem;
            color:#9c999c;
        }
        .charact{
            margin-top: 0.4rem;
            display: flex;
            .charact-item{
                margin-right: 0.3rem;
                border-radius: 0.15rem;
                border:1px solid #b3adb3;
                font-size: 0.3rem;
                padding:0.25rem;
                text-align: center;
                color:#9c999c;
            }
        }
        .detail{
            margin: 0.5rem 0 0.6rem;
            display: flex;
            justify-content: space-between;
            .detail-item{
                text-align: center;
                font-weight: bold;
                .detail-item-name{
                   display: inline-block;
                   padding-top: 0.2rem;
                   color:#9c999c; 
                   font-weight: normal;
                   font-size: 0.3rem;
                }
            }
        }
        .why{
            font-weight: bold;
            font-size: 0.4rem;
            .reason{
                margin-top: 0.3rem;
                font-weight: normal;
                font-size: 0.3rem;
                line-height: 0.5rem;
            }
        }
        .belong{
            margin-top: 0.6rem;
            display: flex;
            justify-content: space-between;
            .belong-info{
                font-size: 0.4rem;
                font-weight: bold;
                display: flex;
                align-items: center;
                .agency-img{
                width: 1.2rem;
                height: 1.2rem;
                border-radius: 1rem;
                margin-right: 0.2rem;
                }
                .belong-text{
                    font-size: 0.3rem;
                    font-weight: normal;
                    margin-top: 0.1rem;
                }
            }  
            .chat-icon{
                width: 0.8rem;
                height: 0.8rem;
            }          
        }
        .button{
            margin-top: 0.5rem;
            button {
                color: red;
            }
        }
    }
}
</style>